<?php
namespace app\adminapi\lists\setting\lang;

use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\lang\LangCountry;

/**
 * 国际语言参照列表
 * Class LangCountryLists
 * @package app\adminapi\lists\setting
 */
class LangCountryLists extends BaseAdminDataLists
{

    /**
     * @notes 搜索条件
     * @return array
     */
    public function setSearch(): array
    {
        $where = [];
        if (isset($this->params['keyword'])){
            $where[] = ['code|name','like','%'.$this->params['keyword'].'%'];
        }
        return $where;
    }

    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function lists(): array
    {
        $field = "id,code,name";
        $lists = LangCountry::where($this->setSearch())
            ->limit($this->limitOffset, $this->limitLength)
            ->field($field)
            ->order('id desc')
            ->select()
            ->toArray();

        return $lists;
    }


    /**
     * @notes 获取数量
     * @return int
     */
    public function count(): int
    {
        return LangCountry::where($this->setSearch())->count();
    }

}